package com.coamc.xlsunit;

import org.beetl.core.Context;
import org.beetl.core.statement.VarRef;
import org.beetl.sql.core.engine.SQLVarRef;

public class XLSSQLVarRef extends SQLVarRef {
	String attr;
	public XLSSQLVarRef(VarRef ref) {
		super(ref);
		this.varIndex = ref.varIndex;
		attr = ref.token.text;
		

	}

	public Object evaluate(Context ctx) {

		Object value = ctx.vars[varIndex];
		if (value == Context.NOT_EXIST_OBJECT) {
			// 按照表达式取值
			VariableTable vars =  (VariableTable)ctx.getGlobal("vars");
			if(vars==null){
				return super.evaluate(ctx);
			}
			Object o = vars.find(attr);
			if(o==null){
				return super.evaluate(ctx);
			}else{
				return o;
			}
			
		}
		return super.evaluate(ctx);
	}
	

}
